package me.hbz.myblog.servlet.admin;


import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import me.hbz.myblog.dao.ArticleDAO;
import me.hbz.myblog.domain.Article;


@WebServlet("/admin/articleList.do")
public class ArticleListServlet extends HttpServlet{
	
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取分页参数
		String pageStr = request.getParameter("page");
		int pageNumber = 1;
		if (pageStr != null && !"".equals(pageStr)) {
			pageNumber = Integer.valueOf(pageStr);
		}
		//实例化 ArticleDAO
		ArticleDAO articleDAO = new ArticleDAO();
		
		//获取数据

		try {
			List<Article> articleList = articleDAO.findAll(pageNumber, 6);
			//将数据保存request 请求域中
			request.setAttribute("articleList", articleList);
			
			//跳转到articleList.jsp
			request.getRequestDispatcher("/admin/articleList.jsp").forward(request, response);
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	
	}

}
